package com.study.kafka.controller;

import com.study.kafka.handler.KafkaSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/kafaka")
public class KafkaController {

    @Autowired
    private KafkaSender kafkaSender;

    /**
     * 消息发送
     * @param topic
     * @param msg
     * @return
     */
    @PostMapping("/send")
    public String sendMsg(String topic, String msg){
        log.info("sendMsg 发送 topic：{}， msg：{}", topic, msg);
        kafkaSender.sendMessage(topic, msg);
        return "success";
    }
}
